package org.benjamin.lending.controller;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.benjamin.lending.domain.entity.TransactRequest;
import org.benjamin.lending.domain.entity.TransactRequest.Type;
import org.benjamin.lending.domain.form.TransactForm;
import org.benjamin.lending.service.TransactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("manager/transact")
public class ManagerTransactController {
	
	private Logger logger = LogManager.getLogger();
	
	@Autowired
	private TransactService transactService;
	
	@RequestMapping("index")
	public ModelAndView index(@ModelAttribute("transactForm") TransactForm transactForm,Pageable pageable ) {
		ModelAndView modelAndView = new ModelAndView("admin.transact.index");
		Page<TransactRequest> transactRequests = this.transactService.findRequestLogsPage(transactForm,pageable);
		modelAndView.addObject("transactRequests",transactRequests);
		modelAndView.addObject("types",Type.values());
		return modelAndView;
	}
	
	@RequestMapping("details")
	public ModelAndView details(String requestId) {
		logger.info("查询详情情况");
		ModelAndView modelAndView = new ModelAndView("admin/transact/details");
		TransactRequest transactRequest = this.transactService.findRequestDetails(requestId);
		modelAndView.addObject("transactRequest",transactRequest);
		return modelAndView;
	}

}
